﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interop;

namespace XMouse360
{
	/// <summary>
	/// Interaction logic for OSKeyboard.xaml
	/// </summary>
	public partial class OSKeyboard : Window
	{

		[System.Runtime.InteropServices.DllImport("dwmapi.dll", PreserveSig = false)]
		public extern static bool DwmIsCompositionEnabled();

		[System.Runtime.InteropServices.DllImport("dwmapi.dll", PreserveSig = false)]
		static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);

		struct MARGINS
		{
			public MARGINS(Thickness t)
			{
				Left = (int)t.Left;
				Right = (int)t.Right;
				Top = (int)t.Top;
				Bottom = (int)t.Bottom;
			}
			public int Left;
			public int Right;
			public int Top;
			public int Bottom;
		}

		public OSKeyboard()
		{
			InitializeComponent();
			SourceInitialized += new EventHandler(OSKeyboard_SourceInitialized);
		}

		void OSKeyboard_SourceInitialized(object sender, EventArgs e)
		{
			ExtendGlassFrame(this, new Thickness(-1));
			WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
			System.Drawing.Rectangle DrawingScreen = System.Windows.Forms.Screen.GetWorkingArea(new System.Drawing.Point((int)Left, (int)Top));
			Top = DrawingScreen.Height * 0.67;
			Height = DrawingScreen.Height * 0.95 - Top;
			Width = Height * 4;
			Left = DrawingScreen.Width / 2 - (Width / 2);
			Style s = new Style(typeof(Button));
			
			s.Setters.Add(new Setter(Button.FontSizeProperty,(int)(Width* 0.3)));
			

		}

		

		public bool ExtendGlassFrame(Window window, Thickness margin)
		{
			if (!DwmIsCompositionEnabled())
				return false;

			IntPtr hwnd = new WindowInteropHelper(window).Handle;
			if (hwnd == IntPtr.Zero)
				throw new InvalidOperationException("The Window must be shown before extending glass.");

			// Set the background to transparent from both the WPF and Win32 perspectives
			window.Background = Brushes.Transparent;
			HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

			MARGINS margins = new MARGINS(margin);
			DwmExtendFrameIntoClientArea(hwnd, ref margins);
			return true;
		}
	}
}
